//index.js
//获取应用实例
const app = getApp();
// var template = require('../header/header.js');

Page({
    data: {
        page: 1,
        pageSize: 10,
        list: [],
    },
    onLoad: function () {
        this.getList()
    },
    onHide: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        this.setData({
            page: 1
        })
        this.getList();
    },

    getList: function () {
        var _this = this;
        var object = {
            url: app.api.url.package.packageList,
            data: {page: _this.data.page, pageSize: _this.data.pageSize},
            success: function (res) {
                if (res.status == 1) {
                    var list = res.data;
                    _this.setData({
                        list: list
                    });
                } else {
                    app.showToast(res.info);
                }
            },
            complete: function () {
                wx.stopPullDownRefresh() //停止下拉刷新
            }
        }
        app.request(object);
    },

    buy: function (e) {
        var id = e.currentTarget.dataset.id;
        app.request({url: app.api.url.package.orderAdd,
            data:{package_id:id},
            success:function(res){
                wx.showModal({title: '成功', content: '套餐购买成功，系统将自动发起订单。',showCancel:false});
            }
        });
    }
});
